package com.ke.jun.view.widght

import android.content.Context
import android.graphics.*
import kotlin.jvm.JvmOverloads
import android.util.AttributeSet
import android.view.View

class PathDashView @JvmOverloads constructor(
    context: Context?,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

    private val mPaint = Paint().apply {
         style = Paint.Style.STROKE
         strokeWidth = 5f
         color = Color.RED
         isAntiAlias=true
    }

    private val mPaint1 = Paint().apply {
        style = Paint.Style.STROKE
        strokeWidth = 5f
        color = Color.BLUE
        isAntiAlias=true
    }

    private val mPaint2 = Paint().apply {
        style = Paint.Style.STROKE
        strokeWidth = 5f
        color = Color.BLACK
        isAntiAlias=true
    }



    private val mPath=Path().apply {
         moveTo(0f, 300f)
         lineTo(200f, 300f)
         lineTo(400f, 100f)
         lineTo(600f, 300f)
    }

    private val mPath1=Path().apply {
         moveTo(0f, 350f)
         lineTo(200f, 350f)
         lineTo(400f, 150f)
         lineTo(600f, 450f)
    }


    private val mPath2=Path().apply {
        moveTo(0f, 400f)
        lineTo(200f, 400f)
        lineTo(400f, 200f)
        lineTo(600f, 500f)
    }
    private val pPath=Path().apply {
        addCircle(0f, 0f, 5f, Path.Direction.CW)
    }

    private val pPath2=Path().apply {

        moveTo(5f, 0f)
        lineTo(0f, 5f)
        lineTo(10f, 5f)
        lineTo(5f, 0f)
    }


    private val mPathEffect: PathEffect
    private val mPathEffect1: PathEffect
    private val mPathEffect2: PathEffect
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        canvas.drawPath(mPath, mPaint)
        canvas.drawPath(mPath1, mPaint1)
        canvas.drawPath(mPath2, mPaint2)
    }

    init {
        //第二种间隔，小三角
        mPathEffect = PathDashPathEffect(pPath, 20f, 0f, PathDashPathEffect.Style.ROTATE)
        mPathEffect1 = PathDashPathEffect(pPath, 20f, 0f, PathDashPathEffect.Style.TRANSLATE)
        mPathEffect2 = PathDashPathEffect(pPath2, 20f, 6f, PathDashPathEffect.Style.ROTATE)
        mPaint.pathEffect = mPathEffect
        mPaint1.pathEffect = mPathEffect1
        mPaint2.pathEffect = mPathEffect2
    }
}